/*
 * @Author: xinzheYu
 * @Create Time: 2017-09-08 18:58:39
 * @Last Modified By: xinzheYu
 * @Last Modified Time: 2017-09-08 19:24:25
 * @Filename: test.c
 * @function: a input port of test module
 */
#include "parse_metafile.h"
#include "bitfield.h"
#include "peer.h"
#include "dbg.h"

extern Bitmap *bitmap;
extern Peer *peer_head;

int main(int argc, char **argv)
{
    int ret;

    if (argc != 2) {
        printf("Usage: %s [torrent file]\n", argv[0]);
    }

    // 测试 parse_metafile.c 中的函数
    parse_metafile(argv[1]);

    // 测试 bitfield.c 中的函数
    create_bitfield(bitmap, 10);

    all_zero(bitmap);
    ret = get_bit_value(bitmap, 10);
    log_info("bitmap value: %d", ret);

    all_set(bitmap);
    ret = get_bit_value(bitmap, 10);
    log_info("bitmap value: %d", ret);

    print_bitfield(bitmap);
    release_memory_in_bitfield();

    // 测试 peer.c 中的函数
    initialize_peer(peer_head);
    add_peer_node();
    add_peer_node();
    add_peer_node();
    print_peers_data();
    ret = del_peer_node(peer_head->next->next);
    check(ret >= 0, "del_peer_node error");
    print_peers_data();

    release_memory_in_peer();

    return 0;

error:
    return -1;
}

